package cn.org.xwb.main.dto;

import cn.org.xwb.main.utils.RSAUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * 存储 RSA 密钥对
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class RsaKeyPair {

    /**
     * RSA 密钥对
     */
    private Map<String, String> keyPair;

    /**
     * RSA 私钥
     */
    private String privateKey;

    /**
     * RSA 公钥
     */
    private String publicKey;

    /**
     * 为 keyPair 字段赋值，同时为 privateKey publicKey
     * 字段赋值
     *
     * @param keyPair RSA 密钥对
     */
    public void setKeyPair(Map<String, String> keyPair) {
        this.keyPair = keyPair;
        publicKey = RSAUtil.getPublicKeyStrByKeyPairStr(keyPair);
        privateKey = RSAUtil.getPrivateKeyStrByKeyPairStr(keyPair);
    }

}
